home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: chang.unx.sas.com!walker
- From: walker@chang.unx.sas.com (Doug Walker)
- Subject: Re: SasC linker Error:
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <Dnnssy.26K@unx.sas.com>
- Date: Sat, 2 Mar 1996 21:24:34 GMT
- X-Nntp-Posting-Host: chang.unx.sas.com
- References: <dkauppDnEzzs.FsD@netcom.com> <758.6631T1348T796@sn.no> <4h0tsv$dsi@strauss.udel.edu>
- Organization: SAS Institute Inc.
-
- In article <4h0tsv$dsi@strauss.udel.edu>,
- John Pat Corigliano <jcorig@strauss.udel.edu> wrote:
- >I like to use one header file that contains the declarations of all global
- >variables. The "trick" to doing this is to create a macro like so:
- >
- >#ifdef MAIN_C
- >#define Global
- >#define Init(var, val) var = val
- >#else
- >#define Global extern
- >#define Init(var, val) var
- >#endif
-
- This will not work if you use GSTs with your SAS/C project. You cannot
- define data in a header file, only declare it.
-
- I recommend using an "extern" declaration in a header file, then picking
- one .c file and adding a second declaration without the extern keyword.
- You can then add an initializer if you like. Assuming the .c file
- includes the .h file, you'll get a compiler warning if you ever forget
- to keep the definition and the declaration in sync.
-
- BTW, your use of "declare" and "define" is sloppy. A function or data
- item can only be DEFINED once, but it may be DECLARED multiple times.
- A definition always serves as a declaration as well.
-
- A trick of ANSI C, by the way, is that the following is actually a
- DEFINITION, not a declaration, and will cause multiple definition
- problems if found in a header file:
-
- extern int x = 10;
-
- The initializer converts what would otherwise have been a declaration
- into a definition.
-
- --
- ***** / walker@unx.sas.com
- *|_o_o|\\ Doug Walker< BIX, Portal: djwalker
- *|. o.| || \ AOL: weissblau
- | o |//
- ======
- Any opinions expressed are mine, not those of SAS Institute, Inc.
-
-